
<html><head>
<title>flibs/m_vfile - flibs </title>
</head>
<! -- Generated from file 'reporting/m_exception.man' by tcllib/doctools with format 'html'
   -->
<! -- Copyright &copy; 2008 Michael Baudin michael.baudin@gmail.com   -- Copyright &copy; 2008 Arjen Markus arjenmarkus@sourceforge.net
   -->
<! -- CVS: $Id: m_exception.html,v 1.1 2008/06/18 10:36:42 relaxmike Exp $ flibs/m_vfile.n
   -->

<body>
<h1> flibs/m_vfile(n) 1.0  &quot;flibs&quot;</h1>
<h2><a name="name">NAME</a></h2>
<p>
<p> flibs/m_vfile - Manage exceptions





<h2><a name="table_of_contents">TABLE OF CONTENTS</a></h2>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#table_of_contents">TABLE OF CONTENTS</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#synopsis">SYNOPSIS</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#description">DESCRIPTION</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#overview">OVERVIEW</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#simple_use-case">Simple use-case</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#controlling_the_execution">Controlling the execution</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#controlling_output">Controlling output</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#pseudo-catch">Pseudo-catch</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#routines">ROUTINES</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#todo">TODO</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#copyright">COPYRIGHT</a><br>
<h2><a name="synopsis">SYNOPSIS</a></h2>
<p>
<table border=1 width=100% cellspacing=0 cellpadding=0><tr            bgcolor=lightyellow><td bgcolor=lightyellow><table 0 width=100% cellspacing=0 cellpadding=0><tr valign=top ><td ><a href="#1"><strong>exception_raiseFatalError</strong> ( <i class='arg'>message</i> )</a></td></tr>
<tr valign=top ><td ><a href="#2"><strong>exception_raiseError</strong> ( <i class='arg'>message</i> )</a></td></tr>
<tr valign=top ><td ><a href="#3"><strong>exception_raiseWarning</strong> ( <i class='arg'>message</i> )</a></td></tr>
<tr valign=top ><td ><a href="#4"><strong>exception_raiseInformation</strong> ( <i class='arg'>message</i> )</a></td></tr>
<tr valign=top ><td ><a href="#5"><strong>exception_raiseFailure</strong> ( <i class='arg'>message</i> )</a></td></tr>
<tr valign=top ><td ><a href="#6"><strong>exception_setstoponerror</strong> ( <i class='arg'>stoponerror</i> )</a></td></tr>
<tr valign=top ><td ><a href="#7"><strong>exception_initcounter</strong> ( )</a></td></tr>
<tr valign=top ><td ><a href="#8"><strong>exception_getcounter</strong> ( )</a></td></tr>
<tr valign=top ><td ><a href="#9"><strong>exception_report</strong> ( )</a></td></tr>
<tr valign=top ><td ><a href="#10"><strong>exception_setlogunit</strong> ( <i class='arg'>unitnumber</i> )</a></td></tr>
<tr valign=top ><td ><a href="#11"><strong>exception_getlogunit</strong> ( ) result ( logunit )</a></td></tr>
<tr valign=top ><td ><a href="#12"><strong>exception_logactive</strong> ( <i class='arg'>bool</i> )</a></td></tr>
<tr valign=top ><td ><a href="#13"><strong>exception_islogactive</strong> ( ) result ( islogactive )</a></td></tr>
<tr valign=top ><td ><a href="#14"><strong>exception_catch</strong> ( <i class='arg'>callback</i> <i class='arg'>, status</i> ) result ( islogactive )</a></td></tr>
</table></td></tr></table>
<h2><a name="description">DESCRIPTION</a></h2>
<p>

Provides services to generate different levels of exceptions
and display the message of the exception.
Five levels of exceptions can be generated, from the lowest
to the highest level :
<ul>
<li> information, warning : just print a message and continue
<br><br>
<li> error, fatal_error and failure : prints a message and stop the execution
</ul>

<h2><a name="overview">OVERVIEW</a></h2>
<p>

<h3><a name="simple_use-case">Simple use-case</a></h3>
<p>

Suppose that one would like to compute the square root of one
real value. The &quot;compute_sqrt&quot; function takes one positive real argument,
and if the argument is negative, one cannot compute the square root so
that one would generate an error. In the following example, extracted from the
unit tests included in the project, one uses the static method &quot;exception_raiseError&quot;
to display a user-friendly message and stop the execution of the program
 
<p><table><tr><td bgcolor=black>&nbsp;</td><td><pre class='sample'>
    function compute_sqrt ( value ) result ( root )
      use m_exception
      implicit none
      real, intent(in) :: value
      real :: root
      if ( value &lt; 0. ) then
        call exception_raiseError ( &quot;Value is negative in compute_sqrt&quot; )
      else 
        root = sqrt ( value )
      endif
   end function compute_sqrt

   real :: root
   root = compute_sqrt ( -1. )
</pre></td></tr></table></p>
 
 In the previous example, the standard output is written so that the
 following message appears on screen.

<p><table><tr><td bgcolor=black>&nbsp;</td><td><pre class='sample'>
   Error.
   Message: Value is negative in compute_sqrt
</pre></td></tr></table></p>

<h3><a name="controlling_the_execution">Controlling the execution</a></h3>
<p>
 
 The client code can control the behaviour of the component each time
 an exception is raised.
 The default behaviour is to stop the execution. This can be modified
 by calling &quot;exception_setstoponerror&quot; in order to continue the execution,
 even if error, fatal error or failure exceptions are raised.

<p>
   In the following example, the static method &quot;exception_setstoponerror&quot; is 
   called so that an error does not interrupt the execution.

<p><table><tr><td bgcolor=black>&nbsp;</td><td><pre class='sample'>
   call exception_setstoponerror ( .false. )
   call exception_raiseError ( &quot;There is an error, but the execution will continue.&quot; )
</pre></td></tr></table></p>

<h3><a name="controlling_output">Controlling output</a></h3>
<p>

   The default behaviour is to write messages onto the standard output
   each time an exception is raised.
   This can be modified in two ways.
<ul>
<li> the first possibility is to disable the writing of the messages 
     with &quot;exception_logactive&quot;. This feature might be useful in the case
     where a component has known bugs but generates lots of unwanted
     exceptions messages.
<br><br>
<li> the second possibility is to connect the component to an existing unit
     with &quot;exception_setlogunit&quot;, so that the messages are written
     on the given logical unit number. 
     This allows for example to write on an existing log file, may be the log 
     file manage by the m_logger component included in the project.
</ul>

<p>
   In the following example, the client code first disables all output,
   set &quot;stoponerror&quot; to false and generates an error which is not displayed
   and does not interrupt the execution.

<p><table><tr><td bgcolor=black>&nbsp;</td><td><pre class='sample'>
   call exception_setstoponerror ( .false. )
   call exception_logactive ( .false. )
   call exception_raiseError ( &quot;This message will not be displayed and the execution will continue.&quot; )
   call exception_logactive ( .true. )
   call exception_raiseError ( &quot;This message WILL be displayed and the execution will continue.&quot; )
</pre></td></tr></table></p>

   In the following example, the client code connect the m_exception component to 
   an existing unit so that the exception messages are written onto a client log file.

<p><table><tr><td bgcolor=black>&nbsp;</td><td><pre class='sample'>
     log_fileunit = 12
     call exception_setstoponerror ( .false. )
     open ( log_fileunit , FILE= &quot;log_file.log&quot; )
     call exception_setlogunit ( log_fileunit )
     call exception_raiseError ( &quot;This message will be written in log_file.log and the execution will continue.&quot; )
     call exception_setlogunit ( 0 )
     call exception_raiseError ( &quot;This message will be written on standard output and the execution will continue.&quot; )
     close ( log_fileunit )
</pre></td></tr></table></p>

   In the following example, the client code connects the m_exception component to 
   the logfile manage by m_logger. This way, the exception messages are collected in the 
   unique log file of the client code.

<p><table><tr><td bgcolor=black>&nbsp;</td><td><pre class='sample'>
     call log_startup ( &quot;log_file.log&quot; , append=.true. )
     call log_cget ( &quot;logfileunit&quot; , log_fileunit )
     call exception_setstoponerror ( .false. )
     call exception_setlogunit ( log_fileunit )
     call exception_raiseError ( &quot;This message will be written in log_file.log and the execution will continue.&quot; )
     call log_shutdown ()
</pre></td></tr></table></p>

<h3><a name="pseudo-catch">Pseudo-catch</a></h3>
<p>

The client code can use a pseudo-catch system which provides
a simple way to manage exceptions which are raised at a lower
level in the call stack. This allows to provide special
treatments when exceptions are generated, without modifiying
all lower level subroutines/function, but just by inserting
exception management when needed.
Suppose that you have a subroutine which source code is the following.

<p><table><tr><td bgcolor=black>&nbsp;</td><td><pre class='sample'>
     subroutine yoursubroutine ()
       use m_exception, only : exception_raiseFatalError
       implicit none
       [...]
       call exception_raiseFatalError ( &quot;Wrong blabla in yoursubroutine&quot; )
       [...]
     end subroutine yoursubroutine
</pre></td></tr></table></p>

   When calling the subroutine &quot;yoursubroutine&quot;, one may wonder if exceptions
   have been generated so that these errors may be processed, or not.
   One can use the &quot;exception_catch&quot; service to compute the status 
   of one subroutine and manage that status.

<p><table><tr><td bgcolor=black>&nbsp;</td><td><pre class='sample'>
     use m_exception, only : exception_catch, &amp;
         EXCEPTION_INFORMATION, &amp;
         EXCEPTION_WARNING &amp;
         EXCEPTION_ERROR &amp;
         EXCEPTION_FATAL_ERROR &amp;
         EXCEPTION_FAILURE
     integer :: status
     call exception_catch ( yoursubroutine , status )
     select case ( status )
     case ( EXCEPTION_INFORMATION )
        write(6,*) &quot;Information&quot;
     case ( EXCEPTION_WARNING )
        write(6,*) &quot;Warning&quot;
     case ( EXCEPTION_ERROR , EXCEPTION_FATAL_ERROR , EXCEPTION_FAILURE )
        write(6,*) &quot;Fatal error&quot;
     case default
        write(6,*) &quot;No problem, continue.&quot;
     end select
</pre></td></tr></table></p>

<h2><a name="routines">ROUTINES</a></h2>
<p>

<dl>

<dt><a name="1"><strong>exception_raiseFatalError</strong> ( <i class='arg'>message</i> )</a><dd>

<dl>
<dt><strong>character(len=*), intent(in) ::</strong> <i class='arg'>message</i><dd>
</dl>
Generates a fatal error message and stops the execution.


<br><br>
<dt><a name="2"><strong>exception_raiseError</strong> ( <i class='arg'>message</i> )</a><dd>

<dl>
<dt><strong>character(len=*), intent(in) ::</strong> <i class='arg'>message</i><dd>
</dl>
Generates an error message and stops the execution.

<br><br>
<dt><a name="3"><strong>exception_raiseWarning</strong> ( <i class='arg'>message</i> )</a><dd>

<dl>
<dt><strong>character(len=*), intent(in) ::</strong> <i class='arg'>message</i><dd>
</dl>
Generates a warning message.


<br><br>
<dt><a name="4"><strong>exception_raiseInformation</strong> ( <i class='arg'>message</i> )</a><dd>

<dl>
<dt><strong>character(len=*), intent(in) ::</strong> <i class='arg'>message</i><dd>
</dl>
Generates an information message.

<br><br>
<dt><a name="5"><strong>exception_raiseFailure</strong> ( <i class='arg'>message</i> )</a><dd>

<dl>
<dt><strong>character(len=*), intent(in) ::</strong> <i class='arg'>message</i><dd>
</dl>
Generates a failure message and stops the execution

<br><br>
<dt><a name="6"><strong>exception_setstoponerror</strong> ( <i class='arg'>stoponerror</i> )</a><dd>

<dl>
<dt><strong>logical, intent(in) ::</strong> <i class='arg'>message</i><dd>
</dl>
If <i class='arg'>stoponerror</i> is true, then when an error, a fatal_error or a failure
is generated, then stop the execution.
If <i class='arg'>stoponerror</i> is false, then the same exceptions do not stop the
execution.



<br><br>
<dt><a name="7"><strong>exception_initcounter</strong> ( )</a><dd>

<dl>
<dt><strong>logical, intent(in) ::</strong> <i class='arg'>message</i><dd>
</dl>
Reset to 0 all the exceptions counters.

<br><br>
<dt><a name="8"><strong>exception_getcounter</strong> ( )</a><dd>

<dl>
<dt><strong>integer, dimension(1:EXCEPTION_SIZE), intent(out) ::</strong> <i class='arg'>counter</i><dd>
</dl>
Returns an array of size EXCEPTION_SIZE indicating the number
of exceptions of each type. The value of <i class='arg'>excepcounters ( iexcept )</i>
is the total number of exceptions of type #iexcept generated since the begining 
of the execution. The possible values for iexcept are the following.
<br><br>
<ul>
<li> counter ( EXCEPTION_INFORMATION ) : total number of information exceptions raised
<br><br>
<li> counter ( EXCEPTION_WARNING ) : total number of warning exceptions raised
<br><br>
<li> counter ( EXCEPTION_ERROR ) : total number of error exceptions raised
<br><br>
<li> counter ( EXCEPTION_FATAL_ERROR ) : total number of fatal error exceptions raised
<br><br>
<li> counter ( EXCEPTION_FAILURE ) : total number of failure exceptions raised
</ul>

<dt><a name="9"><strong>exception_report</strong> ( )</a><dd>

Writes on the current exception unit number a report
which details the number of exceptions of all types
since the begining of the execution or the last reset of
all counters.


<br><br>
<dt><a name="10"><strong>exception_setlogunit</strong> ( <i class='arg'>unitnumber</i> )</a><dd>

<dl>
<dt><strong>integer, intent(in) ::</strong> <i class='arg'>unitnumber</i><dd>
</dl>
Set the unit number onto which the messages are output.
If the unitnumber is negative or 0, the messages are written
to the standard output (unit *).
Note : a unitnumber equals to 6 is generally the standard output, 
but this may depend on the fortran compiler.

<br><br>
<dt><a name="11"><strong>exception_getlogunit</strong> ( ) result ( logunit )</a><dd>

<dl>
<dt><strong>integer ::</strong> <i class='arg'>logunit</i><dd>
</dl>
Returns the positive unit number onto which the messages are output,
if enabled or a negative integer if the feature is disabled.


<br><br>
<dt><a name="12"><strong>exception_logactive</strong> ( <i class='arg'>bool</i> )</a><dd>

<dl>
<dt><strong>logical, intent(in) ::</strong> <i class='arg'>bool</i><dd>
</dl>
If the boolean argument <i class='arg'>bool</i> is true, enable the logging 
of the exceptions messages.
If the boolean argument <i class='arg'>bool</i> is false, disable the logging
of the exceptions messages.


<br><br>
<dt><a name="13"><strong>exception_islogactive</strong> ( ) result ( islogactive )</a><dd>

<dl>
<dt><strong>logical ::</strong> <i class='arg'>islogactive</i><dd>
</dl>
Returns .true. if the current exception messages are written,
either on standard output or into a log file.


<br><br>
<dt><a name="14"><strong>exception_catch</strong> ( <i class='arg'>callback</i> <i class='arg'>, status</i> ) result ( islogactive )</a><dd>

<dl>
<dt><strong>integer, intent(out) ::</strong> <i class='arg'>status</i><dd>
</dl>
<p><table><tr><td bgcolor=black>&nbsp;</td><td><pre class='sample'>
    interface interfacecallback
       subroutine callback ()
       end subroutine callback
    end interface interfacecallback
</pre></td></tr></table></p>
Calls the given subroutine <i class='arg'>callback</i> and set <i class='arg'>status</i> as an 
the integer associated with last exception, higher level, code or 0 if no exception
was raised.
Caution : the internal algorithm is based on the exception counters,
which implies that any call to exception_initcounter in the client
code can result in a wrong status.




</dl>

<h2><a name="todo">TODO</a></h2>
<p>

<h2><a name="copyright">COPYRIGHT</a></h2>
<p>
Copyright &copy; 2008 Michael Baudin michael.baudin@gmail.com<br>
Copyright &copy; 2008 Arjen Markus arjenmarkus@sourceforge.net<br>
</body></html>